<template>
  <div v-if="isShow">
    <div v-if="goods?.list.length" flex flex-wrap>
      <div style="width:50%" v-for="(item, index) in goods.list" :key="index">
        <twoRow :res="item" />
      </div>
    </div>
    <empty mt-100rpx v-else />
  </div>
</template>

<script setup lang="ts">
import { getGoodsList } from '@/api/goods';
import empty from '@/components/empty/index.vue';
import twoRow from '@/components/goods-list/2row.vue';
import { onLoad, onReachBottom, onShow } from '@dcloudio/uni-app';
const isShow = ref<boolean>(false)
const routerVal = ref<any>({})
const goods = ref<any>({
  list: [],
  data: {

  }
})
const params = ref<any>({
  pageNumber: 1,
  pageSize: 10,
  keyword: "",
  storeCatId: "",
  storeId: "",
})
async function init() {
  const res = await getGoodsList(params.value)
  isShow.value = true
  if (res.data.success) {
    goods.value.list.push(...res.data.result.records)
    goods.value.data = res.data.result
  }
}



onLoad((options: any) => {
  routerVal.value = options
  params.value.storeCatId = options.id
  params.value.storeId = options.storeId
  uni.setNavigationBarTitle({
    title: options.title
  })
  init()
})

onReachBottom(() => {
  if (params.value.pageNumber * params.value.pageSize < goods.value.data.total) {
    params.value.pageNumber++
    init()
  }
})
</script>

<style scoped></style>
